/*
 * File:    VariableStoreArray.java
 * Created: 01-Mar-2009
 * Version: $Id$
 *
 * COPYRIGHT (C) 2009, Bitgate Mobile, LLC.  All Rights Reserved.
 *
 * software@bitgatemobile.com
 */

package com.webplasm.store;

import java.util.ArrayList;
import java.util.List;

import com.webplasm.store.VariableContainer.VariableType;

/**
 * The <code>VariableStoreArray</code> object is used to store objects in an array form, meaning objects are FIFO
 * order as an array.  The objects can be of any valid <code>VariableStoreInterface</code> object, so this means
 * that arrays of arrays or arrays of hashes of arrays, etc. can be added.
 * 
 * @author kenji
 * @since Webplasm 2.0
 */
public class VariableStoreArray extends AbstractVariableStore {
	private List<VariableStoreInterface> list;
	
	public VariableStoreArray() {
		list = new ArrayList<VariableStoreInterface>();
	}
	
	public VariableType getType() {
		return VariableType.ARRAY;
	}
	
	@Override
	public boolean isIterative() {
		return true;
	}

	@Override
	public boolean isArray() {
		return true;
	}
	
	@Override
	public void setValue(Object object) {
		if (object instanceof VariableStoreInterface) {
			list.add((VariableStoreInterface) object);
		} else {
			throw new RuntimeException("Unable to add object of type '" + object.getClass().getName() + "', must be " +
					"VariableStoreInterface.");
		}
	}
	
	@Override
	public Object getObject() {
		return list;
	}
}
